import datetime
import math


# 计算两个日期大小
def time_cmp(first_time, second_time):
    # 由于有效期获取后会有小数数据
    firstTime = datetime.datetime.strptime(str(first_time).split('.')[0], "%Y-%m-%d %H:%M:%S")
    secondTime = datetime.datetime.strptime(str(second_time), "%Y-%m-%d %H:%M")
    number = 1 if firstTime > secondTime else 0
    return number


# 计算停车时间
def priceCalc(inDate, outDate):
    if '.' in str(inDate):
        inDate = str(inDate).split('.')[0]
        inDate = datetime.datetime.strptime(inDate, "%Y-%m-%d %H:%M:%S")
        print('特殊处理')
    else:
        inDate = datetime.datetime.strptime(inDate, "%Y-%m-%d %H:%M")
    outDate = datetime.datetime.strptime(str(outDate), "%Y-%m-%d %H:%M")
    rtn = outDate - inDate
    # 计算停车多少小时（往上取整）
    y = math.ceil(rtn.total_seconds() / 60 / 60)
    return y